<template>
  <div class="home">
        <van-tabs v-model="activeIndex" animated>
          <van-tab v-for="item in channelList" :title="item.name" :key="item.id">
            <!-- 内容列表 -->
            <article-list :channelId="item.id"></article-list>
          </van-tab>
        </van-tabs>
     <div class="btn-wrapper">
       <zgticon class="boke-icon" name="search"></zgticon>
       <zgticon @click.native="showAllchannels" class="boke-icon" name="channel"></zgticon>
     </div>
     <article-channel v-model="isShowChannel"       :myChannels="channelList"
      :activeIndex="activeIndex"
      @update:activeIndex="(index)=>{activeIndex=index}"
      @changeChannel="changeChannel"
     ></article-channel>
     <!--
       频道
      v-model:
      :value
      @change=""

    :activeIndex="activeIndex" 动态绑定activeIndex属性传值给子组件
    @update:activeIndex="(index)=> {activeIndex=index}"
    监听子组件发布的update:activeIndex事件并且将传入的参数index赋值给activeIndex
    相当于
    :activeIndex.sync="activeIndex"
    -->
  </div>
</template>

<script>
import { getUserchannels } from '@/api/channel.js'
import articleList from './components/article-list.vue'
import articleChannel from './components/article-channel.vue'
export default {
  // 用keep-alive include缓存组件时需要在组件中有name属性
  name: 'Home',
  components: {
    articleList,
    articleChannel
  },
  methods: {
    // 改变我的频道
    changeChannel (channels) {
      console.log('改变了数据', channels)
      this.channelList = channels
    },
    // 点击列表图标显示所有可选频道 图标的点击事件要加.native
    showAllchannels () {
      this.isShowChannel = true
    }
  },
  data () {
    return {
      // 标签列表
      channelList: [],
      isShowChannel: false,
      activeIndex: 0
    }
  },
  async  created () {
    this.channelList = (await getUserchannels()).channels
    console.log(this.channelList)
  }
}

</script>
<style scoped lang="less">
// 穿透的意思。 因为你在写vantUI、elementUI代码的时候，很多内置的样式改不掉的。
// 修改内置样式 需要穿透。不然有的浏览器或者是某些情况下 是不生效的。
// >>> 、/deep/、::v-deep
::v-deep .van-tabs {
  height: 100%;
  display: flex;
  flex-direction: column;
  .van-tabs__line {
    background: @boke-color;
    height: 2px;
    width: 32px;
  }
  .van-tab {
    color: #9EA1AE;
  }
  .van-tab--active {
    font-size: 18px;
    color: #333;
  }
  .van-tabs__wrap {
    padding-right: 86px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
  }
  .van-tabs__content {
    flex: 1;
    overflow: auto;
    // padding-bottom: 50px;
    padding-bottom: 0;
  }
  // .van-list {
  //   height: 100%;
  // }
  .van-tab__pane {
    height: 100%;
  }
}

.home {
  flex: 1;
  .btn-wrapper {
    position: absolute;
    right: 0;
    top: 0;
    width: 174px;
    height: 80px;
    background: #fff;
    display: flex;
    align-items: center;
    .boke-icon {
      flex: 1;
      text-align: center;
      font-size: 36px;
    }
    &::before {
      content: "";
      width: 40px;
      height: 88px;
      position: absolute;
      left: -40px;
      top: 0;
      background: linear-gradient(to right, rgba(255,255,255,0), #fff);
    }
  }
}
</style>
